#include "settings.h"
#include <QTime>  // 添加这一行

Settings::Settings(const QString &organization, const QString &application)
    : settings(new QSettings(organization, application)) {}

void Settings::saveLastDirectories(const QString &source, const QString &target) {
    settings->setValue("last_source_directory", source);
    settings->setValue("last_target_directory", target);
}

void Settings::loadLastDirectories(QString &source, QString &target) {
    source = settings->value("last_source_directory").toString();
    target = settings->value("last_target_directory").toString();
}

void Settings::setAutoBackupEnabled(bool enabled) {
    settings->setValue("auto_backup_enabled", enabled);
}

bool Settings::isAutoBackupEnabled() const {
    return settings->value("auto_backup_enabled", false).toBool();
}

void Settings::setAutoBackupTime(const QTime &time) {
    settings->setValue("auto_backup_time", time);
}

QTime Settings::getAutoBackupTime() const {
    return settings->value("auto_backup_time", QTime()).toTime();
}

void Settings::setAutoBackupInterval(int interval) {
    settings->setValue("auto_backup_interval", interval);
}

int Settings::getAutoBackupInterval() const {
    return settings->value("auto_backup_interval", 3600000).toInt(); // 默认每小时一次
}

QString Settings::getSourceDir() const {
    return settings->value("last_source_directory").toString();
}

QString Settings::getTargetDir() const {
    return settings->value("last_target_directory").toString();
}

void Settings::setSourceDir(const QString &sourceDir) {
    settings->setValue("last_source_directory", sourceDir);
}

void Settings::setTargetDir(const QString &targetDir) {
    settings->setValue("last_target_directory", targetDir);
}


void Settings::save() {
    settings->sync();
}

void Settings::load() {
    settings->sync();
}
